package com.roocon.design_pattern.chapter07_work_thread;

import java.util.Random;

public class WorkerThread extends Thread {

  private final Channel channel;

  private static final Random random = new Random(System.currentTimeMillis());

  public WorkerThread(String name, Channel channel) {
    super(name);
    this.channel = channel;
  }

  @Override public void run() {
    while (true) {
      channel.take().execute();
      try {
        Thread.sleep(random.nextInt(1_000));
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
}
